home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / aie8911.zip / LISTING.2 < prev    next >
Text File  |  1989-08-27  |  3KB  |  85 lines

  1.  
  2.  
  3.                   Listing 2
  4.  
  5.              THE EXTENDED INTERPRETER
  6.  
  7.  
  8.                      % if a stub is there and it
  9.                      % should be used (e.g. no Prolog code
  10.                      % for process, use the stub
  11. do_goal( Goal ) :-
  12.                      % is there a stub for the Goal
  13.     has_stub( Goal, Frame ),
  14.                      % should the stub be used?
  15.     use_the_stub_q(  Frame),
  16.     !,
  17.                      % then definitely use the stub
  18.     do_stub( Frame).
  19.  
  20.                      % If the goal is user-defined to
  21.                      % fail, then make it fail (this
  22.                      % lets the user explore the specified
  23.                      % system)
  24. do_goal( Goal ) :-
  25.     call( failing_goal( Goal)),
  26.     !,
  27.     fail.
  28.  
  29.                      % If the goal is defined in Prolog
  30.                      % source code, then
  31.                      % interpret it using the definition
  32.                      % of Prolog
  33. do_goal( Goal) :-
  34.                      % Is the goal defined in Prolog code?
  35.      defined_as_prolog_goal( Goal ),
  36.                      % display goal purpose from stub
  37.      display_goal_purpose( Goal ),
  38.                      % get body of rule defining Goal
  39.      clause( Goal, Body),
  40.                      % execute rule body
  41.      do_body( Body).
  42.  
  43.                      % Execute goals defined by Prolog system
  44.                      % code
  45. do_goal( Goal) :-
  46.                      % Make sure there is no source code
  47.                      % definition
  48.      not defined_as_prolog_goal( Goal ),
  49.                      % Try the goal using Prolog system
  50.                      % procedures
  51.      call( Goal ).
  52.  
  53.  
  54. /************ do_goal helpers ***********************/
  55.  
  56.                      % Is a goal defined as source code?
  57. defined_as_prolog_goal( Term ) :-
  58.         clause( Term, _),
  59.         !.
  60.  
  61.        % do_body executes Prolog rule bodies
  62.  
  63.                      % Is a goal defined as source code?
  64. do_body( true ) :- !.
  65.  
  66.                      % Execute 'ands' of subgoals
  67.                      % in rule bodies
  68. do_body( ( H , Rest) ) :-
  69.       !,
  70.       do_and( H, Rest).
  71.  
  72.                      % Execute a single goal, by calling
  73.                      % do_goal
  74. do_body( Term) :-
  75.       do_goal( Term).
  76.  
  77.        % do_and executes 'ands' of goals
  78. do_and( Head , Rest) :-
  79.                      % Try the first goal
  80.       do_goal( Head),
  81.                      % Try the other goals
  82.       do_body( Rest).
  83.  
  84. ---------------- end of listing -----------------------------------
  85.